<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>转账管理</title>
    <link rel="stylesheet" type="text/css" href="static/admin/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="static/admin/css/admin.css" />
</head>

<body>
<div class="wrap-container welcome-container">
    <div class="wrap-container clearfix">
        <div class="column-content-detail">
            <div class="layui-form-item">
                <div class="layui-inline" style="margin-bottom: 0">
                    <input type="text" name="title" required lay-verify="required" placeholder="请输入用户手机号"
                           autocomplete="off" class="keywords layui-input">
                </div>
                <button class="layui-btn layui-btn-normal search">搜索</button>
            </div>
            <div class="layui-form" id="table-list">
                <table class="layui-table" lay-even lay-skin="nob">
                    <thead>
                    <tr>
                        <th>转出用户手机号</th>
                        <th>转出用户姓名</th>
                        <th>转入用户手机号</th>
                        <th>转入用户姓名</th>
                        <th>金额(元)</th>
                        <th>时间</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td class="item-turnout">15037677777</td>
                        <td class="item-into">15037677778</td>
                        <td class="item-money">10000</td>
                        <td class="enter">0</td>
                        <td class="item-state">转账申请中</td>
                        <td class="item-time">2019-03-31 09:10:10</td>
                    </tr>
                    </tbody>
                </table>
                <div id="page" class="page-wrap"></div>
            </div>
        </div>
    </div>
</div>

<div class="user-edit-popup">
    <form class="layui-form" id="form">
        <input type="hidden" name="id" id="user-id">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="name" data-name="用户名" required lay-verify="required" placeholder="请输入用户名"
                       autocomplete="off" class="required layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上级</label>
            <div class="layui-input-inline">
                <input type="text" name="superior" data-name="上级" required lay-verify="required" placeholder="请输入上级"
                       autocomplete="off" class="layui-input required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">级别</label>
            <div class="layui-input-inline">
                <input type="text" name="level" data-name="级别" required lay-verify="required" placeholder="请输入级别"
                       autocomplete="off" class="layui-input required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">VIP</label>
            <div class="layui-input-inline">
                <div class="layui-form-item">
                    <select id="isVIP" name="isVIP" lay-verify="">
                        <option value="">是否是VIP</option>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="static/admin/js/baseUrl.js"></script>
<script type="text/javascript">
    layui.use(['layer', 'jquery', 'laypage'], function () {
        var layer = layui.layer;
        var $ = layui.jquery;
        var laypage = layui.laypage;
        // 请求参数
        var pagedata = {
            pageNum: 1,
            pageSize: 10
        };
        // 获取数据
        function getList(params) {
            $.ajax({
                url: baseUrl + '/transfer/selectTransferList?currentNum=1&currentSize=10',
                data: params,
                type: 'get',
                contentType: "application/json",
                dataType: "json",
                crossDomain: true,     //跨域
                xhrFields: { withCredentials: true },//跨域
                success: function (data) {
                    var datas=data;
                    var data = data.data;
                    console.log(1)
                    var content = "";
                    for (var i = 0; i < data.length; i++) {
                        var disabled;
                        if (data[i].status == 2) {
                            disabled = "disabled";
                        } else {
                            disabled = false;
                        }
                        var cont = "<tr>" +
                            "<td class=item-turnout>" + data[i].fromPhone + "</td>" +
                            "<td class=item-into>" + data[i].fromName + "</td>" +
                            "<td class=item-money>" + data[i].toUser + "</td>" +
                            "<td class=enter>" + data[i].toName + "</td>" +
                            "<td class=item-state>" + data[i].money + "</td>" +
                            "<td class=item-time>" + data[i].creatTime + "</td>" +
                            "</tr>"
                        content += cont;
                    }
                    $(".layui-table tbody").html(content);

                    laypage.render({
                        elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
                        ,
                        count: datas.data.length, //数据总数，从服务端得到
                        jump: function (obj, first) {
                            //obj包含了当前分页的所有参数，比如：
                            // console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                            // console.log(obj.limit); //得到每页显示的条数
                            //首次不执行
                            if (!first) {
                                //do something
                                data.currentNum = obj.curr;
                                getList(pagedata)
                            }
                        }
                    });


                },
                error: function () {
                    layer.msg('网络发生故障，请稍后再试', { icon: 0, time: 1000 });
                },
                complete: function () {
                    // layer.close(loading);
                }
            })
        }

        // 初始数据请求
        getList(pagedata);
        $('.search').click(function () {
            pagedata.fromKey = $('.keywords').val();
            // console.log(data);
            //发起请求
            getList(pagedata);
        });

        // 审核转账 测试提交
        $('.layui-table').on('click', '.finish-forward', function () {
            var id = $(this).data('id');
            var data = $(this).parent().parent().siblings();
            var fromUser = data[0].innerhtml;
            var toUser = data[1].innerhtml;
            var money = data[2].innerhtml;
            var remark = data[4].innerhtml;
            var data = {
                id: id,
                fromUser: fromUser,
                toUser: toUser,
                money: money,
                remark: remark
            }
            data = JSON.stringify(data);
            console.log(id)
            layer.confirm('确定通过此条转账申请吗？', { icon: 0 }, function (index) {
                var loading = layer.load(1, { shade: [0.3, '#000'] });
                layer.close(index);
                // 发起审核通过请求
                $.ajax({
                    url: baseUrl + '/transfer/insertOrUpdateTransfer',
                    data: data,
                    type: 'post',
                    contentType: "application/json",
                    dataType: "json",
                    crossDomain: true,     //跨域
                    xhrFields: { withCredentials: true },//跨域
                    success: function (data) {
                        console.log(data, 123);
                    },
                    error: function () {
                        layer.msg('网络发生故障，请稍后再试', { icon: 0, time: 1000 });
                    },
                    complete: function () {
                        layer.close(loading);
                    }
                })
            })
        })
    })
</script>
</body>

</html>
